package splug.cjk;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import splug.cjk.packet.BBSCarPoolPacket;
import splug.cjk.packet.FriendPacket;

public class ReportRead extends Thread {

	private InputStream is;
	private OutputStream os;
	
	public ReportRead(InputStream is, OutputStream os) {
		super();
		this.is = is;
		this.os = os;
	}

	@Override
	public void run() {
		super.run();
		
		try {
			ObjectInputStream input = new ObjectInputStream(is);
			FriendPacket packet = (FriendPacket) input.readObject();
			String id = packet.getId();
			
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/carpool?useUnicode=true&characterEncoding=euckr","root","apmsetup");
			Statement stmt = conn.createStatement();

			String query = "select you, reason, istreat from report where id = '" + id + "'";

			stmt.execute("SET CHARACTER SET euckr");
			stmt.execute("set names euckr");

			ResultSet rs1 = stmt.executeQuery(query);
			
			ArrayList<String> content = new ArrayList<String>();			

			while(rs1.next()){
				String str1 = rs1.getString("you");
				String str2 = rs1.getString("reason");
				String str3 = null;
				int treat = rs1.getInt("istreat");
				if(treat == 0){
					str3 = "처리중";
				}
				else{
					str3 = "처리완료";
				}
				
				
				String str4 = "신고한 ID : " + str1 + "\n신고 사유 : " + str2 +
				"\n처리현황 : " + str3;
				
				content.add(str4);
			}
			
			packet = new FriendPacket(content, null, null);
			ObjectOutputStream output = new ObjectOutputStream(os);
			output.writeObject(packet);
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
